﻿using System;
using BloggerAutoPoster.Infrastructure.Models;
using BloggerAutoPoster.Common.Mvvm;

namespace BloggerAutoPoster.Infrastructure.AlertConfirmBox
{
    public class SendMsg
    {
        static SendMsg()
        {
            App.Messenger.Register<string>("AlertSysResult", alertSysResult);
        }

        #region Fields (3)

        static Action<AlertConfirmBoxModel> _cancelled;
        static Action<AlertConfirmBoxModel> _confirmed;
        static AlertConfirmBoxModel _input;

        #endregion Fields

        #region Methods (2)

        // Public Methods (1) 

        public static void ShowMsg(AlertConfirmBoxModel input,
                            Exception ex = null,
                            Action<AlertConfirmBoxModel> confirmed = null,
                            Action<AlertConfirmBoxModel> cancelled = null)
        {
            _cancelled = cancelled;
            _confirmed = confirmed;
            _input = input;
            App.Messenger.NotifyColleagues("MyMessengerService", input);
        }
        // Private Methods (1) 

        static void alertSysResult(string res)
        {
            switch (res)
            {
                case "Confirmed":
                    if (_confirmed != null)
                        _confirmed.Invoke(_input);

                    break;
                case "Cancelled":
                    if (_cancelled != null)
                        _cancelled.Invoke(_input);

                    break;
            }
        }

        #endregion Methods
    }
}
